package com.examination.client.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.examination.client.annotation.PassToken;
import com.examination.client.domian.dto.*;
import com.examination.client.domian.vo.QueryUserListVO;
import com.examination.client.entity.UserInfo;
import com.examination.client.service.IUserInfoService;
import com.examination.client.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author xiaodong
 * @since 2021-10-20
 */
@Slf4j
@RestController
@RequestMapping("/userInfo")
@Api(tags = "用户模块")
@CrossOrigin(origins = "*")
public class UserInfoController {

    @Resource
    private IUserInfoService userInfoService;

    @ApiOperation("app用户列表")
    @GetMapping("/app/list")
    public Result<Page<QueryUserListVO>> appList(QueryUserDTO queryUserDTO){
        return Result.success(userInfoService.appList(queryUserDTO));
    }

    @ApiOperation("系统用户列表")
    @GetMapping("/system/list")
    public Result<Page<QueryUserListVO>> systemList(QueryUserDTO queryUserDTO){
        return Result.success(userInfoService.systemList(queryUserDTO));
    }

    @ApiOperation("添加用户")
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody @Validated UserInfoDTO userInfoDTO)throws Exception{
       return Result.success(userInfoService.save(userInfoDTO));
    }

    @GetMapping("/detail")
    @ApiOperation("详情")
    public Result<UserInfo> detail(@RequestParam("id") String id) {
        return Result.success(userInfoService.getById(id));
    }

    @ApiOperation("删除用户")
    @DeleteMapping("/delete")
    public Result<Boolean> deleteUser(@RequestParam("id") String userId)throws Exception{
        return Result.success(userInfoService.deleteUser(userId));
    }

    @ApiOperation("用户信息修改")
    @PutMapping("/modify")
    public Result<Boolean> modify(@RequestBody @Validated UserInfoDTO userInfoDTO)throws Exception{
        return Result.success(userInfoService.modify(userInfoDTO));
    }

    @ApiOperation("查询登录人账户信息")
    @PutMapping("/info")
    public Result<AccountDTO> info(@RequestParam("phone") String phone)throws Exception{
        return Result.success(userInfoService.info(phone));
    }

    @ApiOperation("查询登录人菜单列表")
    @GetMapping("/menu_list")
    public Result<List<MenuSearchDTO>> menuList(@RequestParam("userId") Integer userId,
                                                @RequestParam(value = "selectStatus", required = false) Integer select_status)throws Exception{
        return Result.success(userInfoService.listMenu(userId, select_status));
    }

    @ApiOperation("用户可操作子站点信息修改")
    @PutMapping("/modifyAppSite")
    public Result<Boolean> modifyAppSite(@RequestBody @Validated UserInfoDTO userInfoDTO)throws Exception{
        return Result.success(userInfoService.modifyAppSite(userInfoDTO));
    }

    @ApiOperation(value = "获取 App 版本信息")
    @GetMapping(value = "/info/appVersion")
    @PassToken
    public Result<AppVersionDTO> getAppVersion() {
        AppVersionDTO appVersionResponseDTO = new AppVersionDTO();
        appVersionResponseDTO.setVersion_num("1.0.1");
        appVersionResponseDTO.setBz("测试更新");
        appVersionResponseDTO.setForced(true);
        appVersionResponseDTO.setDownload_url("http://43.143.242.86:8888/down/LPqYrN9JWeCm.apk");
        return Result.success(appVersionResponseDTO);
    }

}

